﻿@model DLMemberPointMS.Entity.ViewModel.MemCardSEditViewModel
@{
    Layout = null;
}
@*积分兑换礼品页面*@
<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <link rel="stylesheet" type="text/css" href="~/layui/css/layui.css" />
    <script src="~/layui/layui.js" type="text/javascript" charset="utf-8"></script>
    <script src="~/layui/jquery-3.4.1.js" type="text/javascript" charset="utf-8"></script>
    <title>积分兑换礼品</title>
    <style type="text/css">
        .layui-input {
            margin-top: 5px;
            height: 30px
        }

        .layui-form-label {
            width: auto;
            padding: 5px 10px;
            margin-top: 5px;
        }
    </style>
    <script>
        layui.use(['table', 'layer'], function () {
            var table = layui.table,
                layer = layui.layer;
            //行内工具栏
            table.on('tool(table)', function (obj) {
                var data = obj.data;
                if (obj.event === 'del') {
                    layer.confirm('真的删除行么', function (index) {
                        $.ajax({
                            type: "get",
                            url: "/Member/MemcardDelResult",
                            data: { id: data.CL_ID },
                            success: function (data) {
                                if (data == '删除成功') {
                                    layer.msg(data, { icon: 1 })
                                    obj.del();
                                } else {
                                    layer.msg(data, { icon: 2 })
                                }
                            },
                            error: function (data) {
                                layer.msg('删除失败', { icon: 2 })
                            }
                        })
                        layer.close(index);
                    });
                } else if (obj.event === 'edit') {
                    // window.location.href='update.aspx?id=' + data.U_ID
                    //layer.alert('编辑行：<br>' + JSON.stringify(data))
                    var id = data.CL_ID;
                    layer.open({
                        type: 2,
                        content: ['/Member/MemcardEdit/' + id + '', 'no'],
                        area: ['500px', '400px'],
                        offset: ['100px', '400px'],
                        skin: 'layui-layer-molv',
                        maxmin: true,
                        id: 'add',
                        end: function () { table.reload('cardList') }
                    });
                }
            });
            //添加按钮点击事件
            $('#new').click(function () {
                layer.open({
                    type: 2,
                    content: ['/Member/MemcardAdd', 'no'],
                    //content: ['/Member/Add', 'no'],
                    area: ['500px', '400px'],
                    offset: ['100px', '400px'],
                    skin: 'layui-layer-molv',
                    maxmin: true,
                    id: 'add',
                    end: function () { table.reload('cardList') }
                });
            })

            //搜索按钮的点击事件
            $('#searh').on('click', function () {
                //获取输入框的值
                var txt = $('#MC').val();
                $.post('/ExchangGift/GetMemCardInfo', { idOrPhone: txt }, function (resault) {
                    layer.msg(resault.msg);
                    $("#MC_Name").text(resault.data.MC_Name);
                    $("#CL_LevelName").text(resault.data.CL_LevelName)
                    $("#MC_Point").text(resault.data.MC_Point)
                    $("#MC_TotalMoney").text(resault.data.MC_TotalMoney)
                    $("#MC_ID").text(resault.data.MC_ID);
                    $("#MC_CardID").text(resault.data.MC_CardID)
                })

            })
            //载入表格
            table.render({
                elem: '#ExchangGift',
                url: '/ExchangGift/GetExchangGiftList',
                id: 'idTest',
                //开启分页
                page: 'true',
                cols: [
                    [{
                        type: 'checkbox'
                    }, {
                        field: 'EG_ID',
                        width: 150,
                        title: '礼品编号',
                        sort: true
                    },
                    {
                        field: 'EG_GiftCode',
                        width: 150,
                        title: '礼品代号',
                        sort: true
                    },
                    {
                        field: 'EG_GiftName',
                        width: 150,
                        title: '礼品名称',
                        sort: true
                    },
                    {
                        field: 'EG_Point',
                        width: 150,
                        title: '所需积分',
                        sort: true
                    },
                    {
                        field: 'EG_Number',
                        width: 150,
                        title: '礼品数量',
                        sort: true,
                    },
                    {
                        field: 'EG_ExchangNum',
                        width: 150,
                        title: '已兑数量',
                        sort: true,
                    },
                    {
                        field: 'EG_Remark',
                        width: 150,
                        title: '备注',
                        sort: true,
                    }
                    ]
                ]
            });
            //马上兑换事件
            $("#DuiHuan").on('click', function () {
                
                if (($('#MC').val()) == "") {
                    layer.msg("请先选择会员");
                    return;
                }
                var MC_ID = $("#MC_ID").text();//会员编码
                var MC_CardID = $("#MC").val();//会员卡号
                var checkStatus = table.checkStatus('idTest'); //idTest 即为基础参数 id 对应的值
                var EG_ID = checkStatus.data[0]["EG_ID"]
                var point = checkStatus.data[0]["EG_Point"]

                $.ajax({
                    url: '/ExchangGift/Create2',
                    type: 'post',
                    data: { MC_ID: MC_ID, MC_CardID: MC_CardID, EG_ID: EG_ID, CO_GavePoint: point },
                    success: function (resault) {
                        if (resault.msg == "兑换成功！") {
                            layer.msg(resault.msg);
                            table.reload('idTest');

                        }
                    },
                    error: function (resault) {

                    }
                })

            })
        })
    </script>
</head>
<body>
    <div>
        <fieldset class="layui-elem-field layui-field-title">
            <legend>查找会员</legend>
            <div class="layui-field-box">
                @using (Html.BeginForm("", "", FormMethod.Post, new { id = "id" }))
                {
                    <div class="layui-form-item">
                        <label class="layui-form-label">卡号/手机：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="title" lay-verify="title" autocomplete="off" class="layui-input" id="MC">
                        </div>
                        <button id="searh" type="button" class="layui-btn layui-btn layui-btn-sm" style="margin-top: 5px;"><i class="layui-icon">&#xe615;搜索</i></button>
                    </div>
                    <table class="layui-table" id="MemCaidInfo">
                        <colgroup>
                            <col width="30">
                            <col width="150">
                            <col width="30">
                            <col width="150">
                            <col>
                        </colgroup>
                        <tbody>
                            <tr>

                                <td>会员姓名:<label id="name"></label></td>
                                <td>
                                    <label hidden="hidden" id="MC_ID"></label>
                                    <label hidden="hidden" id="MC_CardID"></label>

                                    <label id="MC_Name" style="color:red"></label>
                                    @* @Html.EditorFor(model => model.MC_Name, new { htmlAttributes = new { @class = "layui-input", @Value = @ViewBag.MC_Name } })*@
                                </td>
                                <td>当前等级：</td>
                                <td>
                                    <label id="CL_LevelName" style="color:blue"></label>
                                    @*@Html.EditorFor(model => model.CL_ID,new { htmlAttributes = new { @class = "layui-input" ,@Value=@ViewBag.CL_ID} })*@
                                </td>
                            </tr>
                            <tr>
                                <td>当前积分</td>
                                <td>
                                    <label id="MC_Point" style="color:red"></label>
                                    @*@Html.EditorFor(model => model.MC_Point,new { htmlAttributes = new { @class = "layui-input",@Value=@ViewBag.MC_Point } })*@
                                </td>
                                <td>累计消费：</td>
                                <td>
                                    ￥<label id="MC_TotalMoney" style="color:blue"></label>
                                    @*@Html.EditorFor(model => model.MC_TotalMoney,new { htmlAttributes = new { @class = "layui-input" , @Value=@ViewBag.MC_TotalMoney }})*@
                                </td>
                            </tr>
                        </tbody>
                    </table>
                }
            </div>
        </fieldset>
        <table class="layui-inline" lay-data="{id: 'idTest'}" lay-filter="table" id="ExchangGift"></table>
        <span style="color:red">
            双击“兑换数量”的单元格可以修改兑换数量。<br />
            如果还未设置礼品，请点击【礼品管理】
        </span><br />
        <button id="DuiHuan" type="button" class="layui-btn layui-btn layui-btn-sm" style="margin-top: 5px;"><i class="layui-icon">马上兑换</i></button>

    </div>


</body>
</html>
